package interview.huawei.myself.machine_test;

import java.util.*;

public class Main1_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int c = in.nextInt();
        int b = in.nextInt();
        HashMap<Integer, Integer> typeMap = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            int a = in.nextInt();
            int n = 0;
            while (a != 0) {
                n += a % 256;
                a /= 256;
            }
            int r = n % b;
            if (r < c) {
                if (typeMap.get(r) == null)
                    typeMap.put(r, 1);
                else
                    typeMap.put(r, typeMap.get(r) + 1);
            }
        }
//        System.out.println(Collections.max(typeMap.entrySet(), Comparator.comparing(Map.Entry::getValue)).getValue());
        System.out.println(Collections.max(typeMap.values()));
    }
}